/**
 * @Author: wangjian
 * 656876071@qq.com
 * @Date: 2024-08-08 16:14:20
 * @LastEditTime: 2024-08-08 17:17:30
 * @FilePath: src/views/sys/dict/DictHooks.ts
 * @Description:
 */
import {reactive, ref} from "vue";
import useApi, {type SysDictCatalog} from '@/views/sys/api/SysDictCatalogApi'
import {useQueryTable} from "@/core/common/hooks/TableHooks";

export const useEntrance = () => {

    const params = reactive<object>({})

    const columns: Array<any> = [
        {
            title: '字典名称',
            dataIndex: 'dictName',
        },
        {
            title: '字典编码',
            dataIndex: 'code',
        },
        {
            title: '备注',
            dataIndex: 'remark',
        },
        {
            title: '创建时间',
            dataIndex: 'createdTime',
        },
        {
            title: '操作',
            dataIndex: 'operate',
        }
    ]
    const {getPage, deleteById} = useApi()

    const queryTable = useQueryTable(getPage, deleteById, params)
    
    const router = useRouter()
    
    const toOptionView = (dictId:string)=>{
        router.push({path: `/sys/dict/option/${dictId}`})
    }

    return {
        toOptionView,
        params,
        columns,
        ...queryTable
    }
}

import {useSimpleForm} from "@/core/common/hooks/FormHooks";

export const useDictCatalogForm = (callback: Function) => {
    const {add, update, getById} = useApi()
    const PRIMARY_KEY = "dictId"

    const form = ref<SysDictCatalog>({})

    const simpleForm = useSimpleForm(form, PRIMARY_KEY, add, update, getById, callback)

    return {
        form,
        ...simpleForm
    }
}

import useOptionApi,{type SysDictOption} from '@/views/sys/api/SysDictOptionApi'
import {useRouter} from "vue-router"; 
export const useOptionTable = ()=>{
    const params = reactive<object>({})

    const columns: Array<any> = [
        {
            title: '名称',
            dataIndex: 'label',
        },
        {
            title: '值',
            dataIndex: 'val',
        },
        {
            title: '创建时间',
            dataIndex: 'createdTime',
        },
        {
            title: '操作',
            dataIndex: 'operate',
        }
    ]
    const {getPage, deleteById} = useOptionApi()

    const queryTable = useQueryTable(getPage, deleteById, params,false)

    return {
        params,
        columns,
        ...queryTable
    }
}

export const useDictOptionForm = (callback: Function) => {
    const {add, update, getById} = useOptionApi()
    const PRIMARY_KEY = "optionId"

    const form = ref<SysDictOption>({})

    const simpleForm = useSimpleForm(form, PRIMARY_KEY, add, update, getById, callback)

    return {
        form,
        ...simpleForm
    }
}